// 分页组件
import Pagination from "@/components/Pagination";

// 文件上传组件
import FileUpload from "@/components/FileUpload";

// 图片上传组件
import ImageUpload from "@/components/ImageUpload";

// 图片预览组件
import ImagePreview from "@/components/ImagePreview";

// 实时通讯
import webSocket from "@/utils/webSocket/index";

// 引导插件
import intro from "intro.js"; // introjs库

// 个人方法
import funComm from "@/utils/funComm.js";
import { useDict } from "@/utils/dict";
import { download } from "@/utils/request";
import {
  parseTime,
  resetForm,
  addDateRange,
  handleTree,
  selectDictLabel,
  selectDictLabels,
} from "@/utils/xh";

const inall = (app) => {
  /**
   *----------------------------SRT------------------------------->
   * 组件
   */
  app.component("Pagination", Pagination);
  app.component("FileUpload", FileUpload);
  // app.component('DownloadFile', DownloadFile)
  app.component("ImageUpload", ImageUpload);
  app.component("ImagePreview", ImagePreview);
  // ----------------------------END------------------------------->

  /**
   * ----------------------------SRT------------------------------->
   * components/p-components/order
   * 读取基础本地文件
   * 挂载基础组件
   */
  // 读取本地文件（基础）
  const components = import.meta.glob("../components/p-components/*/index.vue");
  // 底层组件
  for (const [key, value] of Object.entries(components)) {
    const keyName = key.split("/")[key.split("/").length - 2];
    app.component(keyName, defineAsyncComponent(value));
  }
  // ----------------------------END------------------------------->

  /**
   * ----------------------------SRT------------------------------->
   * components/p-components/order
   * 读取订单本地文件
   * 挂载订单组件
   */
  // 读取本地文件（订单）
  const orderComponent = import.meta.glob(
    "../components/p-components/order/*/index.vue"
  );
  // 关于订单组件
  for (const [key, value] of Object.entries(orderComponent)) {
    const keyName = key.split("/")[key.split("/").length - 2];
    app.component(keyName, defineAsyncComponent(value));
  }
  // ----------------------------END------------------------------->

  /**
   * ----------------------------SRT------------------------------->
   * components/p-components/storage
   * 读取仓库本地文件
   * 挂载订单组件
   */
  const warehousemangeComponent = import.meta.glob(
    "../components/p-components/storage/*/index.vue"
  );
  // 关于仓库组件
  for (const [key, value] of Object.entries(warehousemangeComponent)) {
    const keyName = key.split("/")[key.split("/").length - 2];
    app.component(keyName, defineAsyncComponent(value));
  }
  // ----------------------------END------------------------------->

  // 全局方法挂载
  app.config.globalProperties.useDict = useDict;
  app.config.globalProperties.download = download;
  app.config.globalProperties.parseTime = parseTime;
  app.config.globalProperties.resetForm = resetForm;
  app.config.globalProperties.handleTree = handleTree;
  app.config.globalProperties.addDateRange = addDateRange;
  app.config.globalProperties.selectDictLabel = selectDictLabel;
  app.config.globalProperties.selectDictLabels = selectDictLabels;
  app.config.globalProperties.webSocket = webSocket;

  // 个人全局方法挂在
  for (let KEY in funComm) {
    app.config.globalProperties[KEY] = funComm[KEY];
  }
  app.config.globalProperties.intro = intro;
};

export default inall;
